package io.lkt.modules.sys.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.lkt.common.validator.ValidatorUtils;
import io.lkt.modules.job.utils.HttpGetPostUtils;
import io.lkt.modules.sys.entity.HeadlineTitleInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.lkt.modules.sys.entity.BArticleTypeInfoEntity;
import io.lkt.modules.sys.service.BArticleTypeInfoService;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;



/**
 * 文章类型信息表
 *
 * @author xss
 * @email dustwas@163.com
 * @date 2019-03-11 10:20:10
 */
@RestController
@RequestMapping("/sys/barticletypeinfo")
public class BArticleTypeInfoController {
    @Autowired
    private BArticleTypeInfoService bArticleTypeInfoService;

    @Value("${serviceUrls}")
    private String serviceUrls;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:barticletypeinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bArticleTypeInfoService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 文章类型
     * @return
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("sys:barticletypeinfo:list")
    public R queryAll(){
        List<BArticleTypeInfoEntity> bArticleTypeInfo=bArticleTypeInfoService.queryAll();
        return R.ok().put("barticletypeinfo", bArticleTypeInfo);
    }

    /**
     * 查询头条标题
     * @return
     */
    @RequestMapping("/HeadlineTitle")
    @RequiresPermissions("sys:barticletypeinfo:list")
    public R HeadlineTitle(){
        List<HeadlineTitleInfo> headTitleMap = bArticleTypeInfoService.HeadlineTitle();
        return R.ok().put("titles",headTitleMap);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
   // @RequiresPermissions("sys:barticletypeinfo:info")
    public R info(@PathVariable("id") Integer id){
        BArticleTypeInfoEntity bArticleTypeInfo = bArticleTypeInfoService.getById(id);

        return R.ok().put("bArticleTypeInfo", bArticleTypeInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:barticletypeinfo:save")
    public R save(@RequestBody BArticleTypeInfoEntity bArticleTypeInfo) throws IOException {
        bArticleTypeInfoService.save(bArticleTypeInfo);
        HttpGetPostUtils.delCache(serviceUrls, "ArticleTypeInfoMapper");
        HttpGetPostUtils.delCache(serviceUrls, "BrandInfoMapper");
        HttpGetPostUtils.delCache(serviceUrls, "UserBrandInfoMapper");
        HttpGetPostUtils.delCache(serviceUrls, "ArticleInfoMapper");
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("sys:barticletypeinfo:update")
    public R update(@RequestBody BArticleTypeInfoEntity bArticleTypeInfo) throws IOException {
        ValidatorUtils.validateEntity(bArticleTypeInfo);
        bArticleTypeInfoService.updateById(bArticleTypeInfo);
        HttpGetPostUtils.delCache(serviceUrls, "ArticleTypeInfoMapper");
        HttpGetPostUtils.delCache(serviceUrls, "BrandInfoMapper");
        HttpGetPostUtils.delCache(serviceUrls, "UserBrandInfoMapper");
        HttpGetPostUtils.delCache(serviceUrls, "ArticleInfoMapper");
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:barticletypeinfo:delete")
    public R delete(@RequestBody Integer[] ids) throws IOException {
        bArticleTypeInfoService.removeByIds(Arrays.asList(ids));
        HttpGetPostUtils.delCache(serviceUrls, "ArticleTypeInfoMapper");
        HttpGetPostUtils.delCache(serviceUrls, "BrandInfoMapper");
        HttpGetPostUtils.delCache(serviceUrls, "UserBrandInfoMapper");
        HttpGetPostUtils.delCache(serviceUrls, "ArticleInfoMapper");
        return R.ok();
    }

}
